<span class='title_page'>Editando Status: <%= @transporte.ndt%></span>
<br/>
<div class="form">
    <% form_for(:transporte, :url => {:controller => 'transportes', :action => 'updatestatus', :id => @transporte}, :html => { :method => :put }) do |f| %>
        <%= error_messages_for :user %>

        <fieldset class="colunas">
            <% tableize @transporte.armazenamentos, :generate_css => false, :cols => 3 do |a| %>
                <div class="coluna-1">
                    <p>
                        <label for="aurora"><%= a.deposito.nome.upcase_br %></label>
                    </p>

                    <div id="sub-<%= a.deposito.nome.downcase_br %>" class="subOpcoesEditar">
                        <% options = {}
                           if a.nil?
                               options = {:include_blank => true}
                           else
                               options = {:selected=> a.nil? ? "" : a.box}
                           end
                        %>
                        <p class="new">
                            <label for="boxAurora">BOX:</label> <br/>
                            <%= select "deposito_#{a.deposito.id}", "box", Array.new(a.deposito.qtbox.to_i + 1){|n| n }, options, {:class => 'box comboBox', :value => a.nil? ? "" : a.box} %>
                        </p>
                        <br class="clear"/>
                    </div>

                    </p>
                </div>
            <% end %>
        </fieldset>

        <fieldset class="colunas">
            <div class="coluna-1">
                <p>
                    <%= f.label :status_id, 'Status:' %>
                    <%= f.select :status_id, @status, {:include_blank => false}, {:class => 'comboBox', :onchange => 'exibeDataFaturmento(this);'} %>
                </p>

                <p id='data_de_faturamento'>
                    <label for="transporte_ended_at">Data de Faturamento:</label> <br/>
                    <%= f.text_field :ended_at,
                            :order => [:day, :month, :year],
                            :maxlength => 10,
                            :ondrop => "return false",
                            :onpaste => "return false",
                            :value => @ended_at,
                            :class => "input-text-layout-dataFaturamento selecionaDataFaturamento dp-applied",
                            :onFocus =>"",
                            :onkeypress => "Mascara('DATA',this,event);" %>
                    -
                    <%= select_hour(@hora,{},{:class => 'combBoxhour'}) %>
                    :
                    <%= select_minute(@minuto,{},{:class => 'combBoxhour'}) %>

                </p>

                <p>
                    <%= f.label :obs_trans, 'Observação:' %>
                    <%= f.text_field :obs_trans, :class => "input-text-layout" %>
                </p>

                <p>
                    <%= f.label :etiqueta, 'Etiqueta:' %>
                    <%= f.check_box :etiqueta, :class => "input-checkbox" %>
                </p>

                <p>
                    <%= f.label :carro, 'Carro:' %>
                    <%= f.check_box :carro, :class => "input-checkbox" %>
                </p>

                <p>
				<%= button_to_function "Enviar", "salvar(#{@deposito.size})", :class => "input-submit" %>
				<%= button_to_function "Voltar", "javascript:window.history.go(-1)", :class => "input-submit" %>					
				</p>
            </div>
        </fieldset>
    <% end -%>
</div>

<script type="text/javascript">

	Event.observe(window, 'load',
		function() {
			exibeDataFaturmento();
		}
	);

	function exibeDataFaturmento(){
			if (($('transporte_status_id') != null) && ($F('transporte_status_id') == <%= $LIB%> || $F('transporte_status_id') == <%= $CDO_CNF%> || $F('transporte_status_id') == <%= $CNDO_CNF%> || $F('transporte_status_id') == <%= $GDO_CNF%> || $F('transporte_status_id') == <%= $SEP_CNF%>  || $F('transporte_status_id') == <%= $CONF_CNF%>)){
				$('data_de_faturamento').show();
				return true;
			}else{
				$('data_de_faturamento').hide();
				return false;
			}
	}

    function validarBOX(){	
		var status = $('transporte_status_id');
		var flag = true;
		if(status != null && (status.value == <%= $FG %> || status.value == <%= $GDO %> || status.value == <%= $GDO_CNF %>)){                  
			$$('select.box').each(
				function(box){
					if(box != null && box.disabled == false && box.value != 0){
						flag = false;
					} 
				}
			);					
			if(flag == false){
				alert('Esse Status(FG, GDO, GDO CNF) não permite que o transporte entre em BOX.');
				status.focus();
				return false;
			}
		}else if(status.value != <%= $FG %> && status.value != <%= $GDO %> && status.value != <%= $GDO_CNF %> && status.value != <%= $CANC %>){
			$$('select.box').each(
				function(box){
					if(box != null && box.disabled == false && box.value == 0){
						flag =  false;
					} 
				}
			);
			if(flag == false){
				alert('Esse Status necessita que todos os Box estejam setados.');
				status.focus();
				return false;				
			}			
		}
		return true;
	}

	function salvar(tamanho){
		status = document.getElementById('transporte_status_id');   
		
		if ( status != null && status.value == ""){
			alert ('O campo STATUS é de preenchimento obrigatório.');
		}else if (validarBOX(tamanho)){
			document.forms[0].submit();
		}
	}
	
                    

</script>